package com.bluemobi.framework.pay.wechat.common;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取客户端IP
 *
 * @author zhangyong
 * @version 1.0
 * @Date 2016-3-4 10:57
 */
public class IpAddressUtil {
    public static String getIpAddr(HttpServletRequest request) {
        if (request.getHeader("x-forwarded-for") == null) {
            return request.getRemoteAddr();
        }
        return request.getHeader("x-forwarded-for");
    }

    public static String formatIpAddr(HttpServletRequest request){
        String ips = getIpAddr(request);
        if(ips.indexOf(",") != -1){
            return ips.split(",")[0];
        }else{
            return ips;
        }
    }
}
